package com.zk.fm;

import java.util.List;

import com.zk.fm.entity.Player;
import com.zk.fm.entity.User;
import com.zk.fm.util.JDBCUtil;

public class Manager {

	public String getNewestVersion() {
		return "1.3.3";
	}

	public boolean login(User user) {
		try {
			JDBCUtil.connectDB();
			return JDBCUtil.login(user);
		} catch (Exception e) {
			System.out.println("e = " + e.toString());
			e.printStackTrace();
		}
		return false;
	}

	public int register(User user) {
		try {
			JDBCUtil.connectDB();
			return JDBCUtil.register(user);
		} catch (Exception e) {
			System.out.println("e = " + e.toString());
			e.printStackTrace();
		}
		return 0;
	}

	public boolean isAccountExist(String account) {
		System.out.println("account = " + account);
		try {
			JDBCUtil.connectDB();
			return JDBCUtil.isAccountExist(account);
		} catch (Exception e) {
			System.out.println("e = " + e.toString());
			e.printStackTrace();
		}
		return true;
	}

	public boolean suggest(String account, String suggestion) {
		try {
			JDBCUtil.connectDB();
			return JDBCUtil.suggest(account, suggestion);
		} catch (Exception e) {
			System.out.println("e = " + e.toString());
			e.printStackTrace();
		}
		return false;
	}

	public List<Player> getAllPlayers(String name) {
		return getPlayersByName(null);
	}

	public List<Player> getPlayersByName(String name) {
		System.out.println("account = " + name);
		try {
			JDBCUtil.connectDB();
			return JDBCUtil.getPlayerByName(name);
		} catch (Exception e) {
			System.out.println("e = " + e.toString());
			e.printStackTrace();
		}
		return null;
	}

}
